package com.kingre.et.util;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class MathMethods {
    public int sum(List<Integer> a) {
        if (a.size() > 0) {
            int sum = 0;

            for (Integer i : a) {
                sum += i;
            }
            return sum;
        }
        return 0;
    }

    public double mean(List<Integer> a) {
        int sum = sum(a);
        double mean = 0;
        mean = sum / (a.size() * 1.0);
        return mean;
    }

    public double median(List<Integer> a) {
        int middle = a.size() / 2;

        if (a.size() % 2 == 1) {
            return a.get(middle);
        } else {
            return (a.get(middle - 1) + a.get(middle)) / 2.0;
        }
    }

    public double sd(List<Integer> a) {
        int sum = 0;
        double mean = mean(a);

        for (Integer i : a)
            sum += Math.pow((i - mean), 2);
        return Math.sqrt(sum / (a.size() - 1)); // sample
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        MathMethods m = new MathMethods();

        List<Integer> c = Arrays.asList(3, 3, 4, 5, 3, 3, 3, 4, 4, 3, 5, 3, 4, 5, 4, 3, 3, 4, 3, 4, 5, 5, 2, 4, 5, 4,
                3, 4, 4, 3, 3, 4, 3, 1, 4, 5, 4, 5, 5, 3, 3, 5, 5, 5, 3, 4, 2, 4, 4, 5, 4, 4, 4, 4, 3, 3, 4, 2, 4, 1,
                3, 2, 3, 3, 4, 3, 3, 3, 2, 5, 3, 4, 3, 2, 3, 3, 4, 4, 4, 4, 3, 3, 4, 5, 2, 5, 5, 5, 4, 5, 5, 5, 5, 5,
                4, 3, 3, 5, 3, 4, 3, 4, 1, 3, 3, 2, 3, 4, 5, 3, 5, 4, 4, 3, 3, 5, 4, 5, 1, 4, 4, 4, 3, 3, 3, 3, 5, 3,
                4, 2, 3, 3, 2, 3, 2, 3, 4, 3, 5, 3, 3, 4, 3, 1, 1, 4, 4, 1, 4, 4, 4, 4, 4, 5, 3, 3, 5, 3, 1, 3, 3, 3,
                4, 4, 5, 5, 5, 4, 5, 2, 5, 3, 3, 3, 3, 4, 5, 3, 5, 4, 4, 2, 1, 4, 3, 3, 4, 3, 3, 4, 4, 4, 3, 3, 3, 4,
                3, 4, 5, 5, 5, 3, 3, 4, 3, 4, 5, 4, 5, 4, 4, 4, 3, 4, 5, 4, 4, 5, 3, 3, 3, 5, 5, 4, 5, 4, 3, 4, 5, 3,
                5, 3, 4, 4, 5, 4, 5, 4, 3, 4, 4, 4, 4, 4, 4, 3, 5, 3, 3, 4, 5, 4, 3, 2, 5, 3, 3, 4, 3, 4, 4, 2, 3, 5,
                3, 4, 3, 4, 3, 3, 4, 4, 3, 4, 4, 3, 3, 5, 4, 4, 3, 5, 5, 3, 5, 5, 5, 3, 2, 3, 5, 1, 3, 3, 1, 2, 4, 2,
                4, 3, 4, 3, 1, 5, 3, 3, 3, 4, 4, 2, 4, 5, 4, 3, 4, 4, 4, 5, 5, 5, 2, 3, 5, 5, 4, 4, 3, 1, 2, 4, 4, 5,
                5, 1, 3, 5, 3, 3, 5, 5, 5, 4, 4, 5, 5, 5, 5, 5, 4, 1, 3, 3, 4, 5, 5, 4, 3, 2, 4, 5, 1, 4, 5, 4, 5, 5,
                5, 3, 2, 4, 1, 5, 5, 5, 2, 5, 5, 1, 4, 5, 2, 1, 3, 5, 5, 5, 5, 1, 3, 5, 5, 1, 2, 3, 5, 3, 1, 5, 4, 3,
                5, 5, 5, 3, 5, 4, 5, 1, 5, 3, 2, 2, 3, 5, 5, 5, 5, 4, 5, 3, 4, 4, 5, 4, 5, 5, 4, 5, 1, 4, 4, 1, 4, 5,
                4, 5, 5, 3, 3, 3, 4, 4, 5, 5, 1, 3, 5, 5, 4, 5, 4, 4, 4, 5, 5, 5, 5, 4, 4, 5, 3, 1, 5, 3, 2, 4, 5, 3,
                5, 3, 3, 5, 5, 5, 5, 2, 4, 3, 5, 5, 4, 5, 4, 5, 5, 4, 4, 3, 5, 1, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4, 3,
                4, 5, 4, 2, 4, 4, 2, 3, 4, 4, 5, 5, 4, 4, 5, 2, 5, 5, 3, 4, 4, 5, 4, 5, 4, 4, 2, 2, 4, 3, 3, 4, 4, 5,
                4, 4, 5, 3, 2, 3, 2, 3, 4, 4, 3, 4, 4, 5, 3, 3, 3, 5, 3, 2, 3, 1, 3, 4, 3, 4, 3, 4, 4, 2, 4, 3, 4, 4,
                4, 3, 3, 4, 2, 4, 3, 5, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 5, 4, 4, 4, 4, 3, 4, 3, 4, 2, 4, 4, 5, 3, 4, 3,
                4, 2, 4, 2, 4, 3, 2, 5, 3, 4, 3, 3, 2, 4, 3, 3, 3, 4, 4, 5, 4, 3, 2, 4, 4, 5, 4, 4, 3, 2, 5, 4, 2, 4,
                5, 5, 2, 4, 4, 4, 4, 3, 5, 2, 2, 4, 3, 2, 3, 3, 5, 5, 3, 4, 4, 5, 5, 4, 4, 5, 4, 5, 5, 4, 4, 4, 3, 4,
                5, 5, 5, 3, 4, 4, 3, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 4, 2, 5, 4, 3, 3, 4, 5, 3, 3, 4, 5, 3, 4, 5, 3, 4,
                3, 5, 4, 3, 4, 3, 4, 4, 4, 3, 4, 3, 2, 4, 4, 2, 4, 4, 5, 3, 3, 4, 3, 5, 5, 1, 4, 2, 4, 4, 4, 4, 5, 4,
                3, 4, 2, 4, 4, 3, 1, 2, 4, 5, 3, 3, 4, 4, 4, 4, 5, 4, 4, 4, 4, 5, 2, 4, 4, 5, 4, 5, 3, 5, 2, 3, 3, 4,
                4, 4, 3, 5, 5, 2, 5, 4, 3, 3, 5, 5, 4, 2, 4, 4, 4, 3, 5, 5, 3, 3, 3, 2, 3, 4, 4, 2, 3, 3, 5, 3, 4, 4,
                2, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 5, 4, 5, 2, 4, 5, 4, 4, 3, 4, 2, 4, 4, 4, 3, 4, 5, 4, 4, 4, 2, 3, 3,
                3, 3, 3, 3, 3, 2, 3, 5, 2, 2, 5, 4, 2, 3, 3, 2, 4, 4, 5, 2, 5, 3, 4, 3, 2, 1, 5, 3, 3, 3, 3, 4, 4, 4);
        Collections.sort(c);
        System.out.println(m.median(c));
        System.out.println(m.mean(c));
        System.out.println(m.sd(c));

    }

}
